package com.victor.controller.web;

import java.util.HashMap;

import org.codehaus.jettison.mapped.NullNamespaceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.victor.entity.ticketorder.TicketOrders;
import com.victor.service.TicketOrderService;
import com.victor.utils.Msg;

@RestController
@RequestMapping("/ticketorder")
public class TicketOrderController {
	@Autowired
	private TicketOrderService ticketOrderService;
	@Autowired
	private LogController logcontroller;

	/**
	 * 票务列表
	 * @param page
	 * @param row
	 * @param flag
	 * @return
	 */
	@RequestMapping("/getall")
	public Msg findAll(int page,int row,String flag,String useflag,String search,String start,String end) {
		PageInfo<TicketOrders> pageInfo = ticketOrderService.selAll(page,row,flag,useflag,search,start,end);
		return Msg.success().add("list", pageInfo);
	}
	
	/**
	 * 票务详情
	 * @param id
	 * @return
	 */
	@RequestMapping("/xiangqing")
	public Msg Xiangqing(Integer id) {
		if (id == null) {
			return Msg.fail("入参失败");
		}
		TicketOrders ticketOrders = ticketOrderService.selByOrderId(id);
		return Msg.success().add("ticketOrders", ticketOrders);
		
	}
	
	/**
	 * 删除订单
	 * @param ids
	 * @return
	 */
	@RequestMapping("/delete")
	public Msg delteteOrder(int[] ids,String adminid,String type) {
		if (ids == null || ids.length<=0 || adminid == null || adminid.isEmpty() || type == null || type.isEmpty()) {
			return Msg.fail("入参错误");
		}
		boolean b = ticketOrderService.deleteOrder(ids);
		logcontroller.addLog(adminid, "删除了票务"+ids,type);
		return Msg.judge(b);
	}
	/**
	 * 修改订单
	 * @param ticketOrders
	 * @return
	 */
	@RequestMapping("/updateorder")
	public Msg updateOrder(TicketOrders ticketOrders,String adminid,String type) {
		if (ticketOrders == null || ticketOrders.getId() == null || adminid == null || adminid.isEmpty() || type == null || type.isEmpty() ) {
			return Msg.fail("入参失败");
		}
		boolean b = ticketOrderService.updateOrder(ticketOrders);
		logcontroller.addLog(adminid, "修改了"+ticketOrders.getId()+"的票务订单",type);
		return Msg.judge(b);
	}
}
